package com.enumdemo.enummethod;

import java.util.EnumSet;
import java.util.Set;

/**
 * 与使用匿名类相比，定义常量相关方法的语法更高效、简洁
 * 
 * @author Administrator
 *
 */
public class CarWash {

	public enum Cycle {

		UNDERBODY {
			void action() {
				System.out.println("Spraying the underbody");
			}
		},
		WHEELWASH {
			void action() {
				System.out.println("Washing the wheels");
			}
		},
		PREWASH {
			void action() {
				System.out.println("Loosening the dirt");
			}
		},
		BASIC {
			void action() {
				System.out.println("The basic wash");
			}
		},
		HOTWAX {
			void action() {
				System.out.println("Applying host wax");
			}
		},
		RINSE {
			void action() {
				System.out.println("Rinsing");
			}
		},
		BLOWDRY {
			void action() {
				System.out.println("Blowing dry");
			}
		};

		abstract void action();

	}

	Set<Cycle> cycles = EnumSet.of(Cycle.BASIC, Cycle.RINSE);

	public void add(Cycle cycle) {
		cycles.add(cycle);
	}

	public void washCar() {
		for (Cycle cycle : cycles) {
			cycle.action();
		}
	}

	public String toString() {
		return cycles.toString();
	}

	public static void main(String[] args) {
		CarWash wash = new CarWash();
		System.out.println(wash);
		wash.washCar();

		wash.add(Cycle.BLOWDRY);
		wash.add(Cycle.BLOWDRY);
		wash.add(Cycle.RINSE);
		wash.add(Cycle.HOTWAX);
		System.out.println(wash);
		wash.washCar();
	}

}
